package com.github.llyb120.qiuyasql.entity;

import com.sun.corba.se.spi.extension.ZeroPortPolicy;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.SneakyThrows;

import java.lang.reflect.Field;
import java.math.BigDecimal;

/**
 * @Author: Administrator
 * @Date: 2020/10/4 16:24
 */
@Data
@AllArgsConstructor
public class TableField {
    private FieldType type;
    private Field field;
    private String name;


    /**
     * 取值
     *
     * @param instance
     * @return
     */
    public Object getValue(Object instance){
        Object value = null;
        try{
            value = field.get(instance);
        } catch (Exception e){ }
        if (value != null) {
            return value;
        }
        switch (type){
            case STRING:
                return "";
            case DECIMAL:
                return BigDecimal.ZERO;
        }
        return null;
    }
}
